﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using Maticsoft.Common;
using System.Drawing;
using LTP.Accounts.Bus;
namespace lcmyjobs.Web.adverts
{
    public partial class List : Page
    {



        lcmyjobs.BLL.adverts bll = new lcmyjobs.BLL.adverts();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["adminName"] != null)
                {
                    //gridView.BorderColor = ColorTranslator.FromHtml(Application[Session["Style"].ToString() + "xtable_bordercolorlight"].ToString());
                    //gridView.HeaderStyle.BackColor = ColorTranslator.FromHtml(Application[Session["Style"].ToString() + "xtable_titlebgcolor"].ToString());
                    btnDelete.Attributes.Add("onclick", "return confirm(\"你确认要删除吗？\")");
                    BindData();
                }
                else
                {
                    Maticsoft.Common.MessageBox.ResponseScript(this, "alert('请先登陆！');top.location.href='../adminlogin2.aspx'");
                }

            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            string idlist = GetSelIDlist();
            if (idlist.Trim().Length == 0)
                return;
            bll.DeleteList(idlist);
            BindData();
        }

        #region gridView

        public void BindData()
        {
            #region
            //if (!Context.User.Identity.IsAuthenticated)
            //{
            //    return;
            //}
            //AccountsPrincipal user = new AccountsPrincipal(Context.User.Identity.Name);
            //if (user.HasPermissionID(PermId_Modify))
            //{
            //    gridView.Columns[6].Visible = true;
            //}
            //if (user.HasPermissionID(PermId_Delete))
            //{
            //    gridView.Columns[7].Visible = true;
            //}
            #endregion

            DataSet ds = new DataSet();
            StringBuilder strWhere = new StringBuilder();
            strWhere.AppendFormat("(ispicdisplay={0}", 1);
            strWhere.Append(" or ispicdisplay is null) ");
            
            if (ddllocation.SelectedValue.ToString() != "100")
            {
                strWhere.AppendFormat(" and locationid={0}", int.Parse(ddllocation.SelectedValue.ToString()));
            }
            ds = bll.GetList(strWhere.ToString());
            gridView.DataSource = ds;
            gridView.DataBind();
        }

        protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gridView.PageIndex = e.NewPageIndex;
            BindData();
        }
        protected void gridView_OnRowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                //e.Row.Cells[0].Text = "<input id='Checkbox2' type='checkbox' onclick='CheckAll()'/><label></label>";
            }
        }
        protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            e.Row.Attributes.Add("style", "background:#FFF");
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                LinkButton linkbtnDel = (LinkButton)e.Row.FindControl("LinkButton1");
                //linkbtnDel.Attributes.Add("onclick", "return confirm(\"你确认要删除吗\")");
                System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)e.Row.FindControl("Image1");
                img.Attributes.Add("onload", "javascript:ResizeImage(this,200,50);");

                //object obj1 = DataBinder.Eval(e.Row.DataItem, "Levels");
                //if ((obj1 != null) && ((obj1.ToString() != "")))
                //{
                //    e.Row.Cells[1].Text = obj1.ToString();
                //}

            }
        }

        protected void gridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //#warning 代码生成警告：请检查确认真实主键的名称和类型是否正确
            int ID = (int)gridView.DataKeys[e.RowIndex].Value;
            bll.Delete(ID);
            DataBind();
        }

        private string GetSelIDlist()
        {
            string idlist = "";
            bool BxsChkd = false;
            for (int i = 0; i < gridView.Rows.Count; i++)
            {
                CheckBox ChkBxItem = (CheckBox)gridView.Rows[i].FindControl("DeleteThis");
                if (ChkBxItem != null && ChkBxItem.Checked)
                {
                    BxsChkd = true;
                    //#warning 代码生成警告：请检查确认Cells的列索引是否正确
                    if (gridView.DataKeys[i].Value != null)
                    {
                        idlist += gridView.DataKeys[i].Value.ToString() + ",";
                    }
                }
            }
            if (BxsChkd)
            {
                idlist = idlist.Substring(0, idlist.LastIndexOf(","));
            }
            return idlist;
        }
        public string getLocationById(string ids)
        {
            int id = int.Parse(ids);
            string[] nameid = new string[] { "首页上中位","首页中上1行位","首页中上2行左1/4","首页中上2行左2/4","首页中上2行左3/4","首页中上2行左4/4","首页中上3行左1/5","首页中上3行左2/5","首页中上3行左3/5",
            "首页中上3行左4/5","首页中上3行左5/5","首页中上4行左1/5","首页中上4行左2/5","首页中上4行左3/5","首页中上4行左4/5","首页中上4行左5/5",
             "求职中心首页上1行位","求职中心首页上2行左1/4",
             "求职中心首页上2行左2/4",
             "求职中心首页上2行左3/4",
             "求职中心首页上2行左4/4",
             "求职中心首页上3行左1/4",
             "求职中心首页上3行左2/4",
             "求职中心首页上3行左3/4",
             "求职中心首页上3行左4/4",
             "招聘中心首页上位",
             "单位介绍左位",
             "猎头服务首页中位",
             "悬赏招聘&bull;悬赏求职首页中位",
             "个人管理中心上位",
             "单位管理中心上位",
             "在校生&bull;应届生首页中上左1/6",
             "在校生&bull;应届生首页中上左2/6",
             "在校生&bull;应届生首页中上左3/6",
             "在校生&bull;应届生首页中上左4/6",
             "在校生&bull;应届生首页中上左5/6",
             "在校生&bull;应届生首页中上左6/6",
             "在校生&bull;应届生首页中中左1/6",
             "在校生&bull;应届生首页中中左2/6",
             "在校生&bull;应届生首页中中左3/6",
             "在校生&bull;应届生首页中中左4/6",
             "在校生&bull;应届生首页中中左5/6",
             "在校生&bull;应届生首页中中左6/6",
             "在校生&bull;应届生首页中下左1/6",
             "在校生&bull;应届生首页中下左2/6",
             "在校生&bull;应届生首页中下左3/6",
             "在校生&bull;应届生首页中下左4/6",
             "在校生&bull;应届生首页中下左5/6",
             "在校生&bull;应届生首页中下左6/6"};
            return nameid[id];
        }

        #endregion


        
        protected string getdisplay(string isdisplay)
        {
            
            string str = "";
            /*
            if (Convert.ToInt16(isdisplay) > 0)
            {
                str = "隐藏";
            }
            else
            {
                str = "显示";
            }
             * */
            return str;
            

        }
          
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e )
        {
            if (e.CommandName == "lbn_display")
            {
                if (e.CommandArgument != null)
                {
                    int aid = Convert.ToInt32( e.CommandArgument );
                    DataSet ds = new DataSet();
                    StringBuilder strWhere = new StringBuilder();
                    
                    strWhere.AppendFormat("aid={0}", aid);
                    
                    ds = bll.GetList(strWhere.ToString());
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        string strset="";
                        string str = ds.Tables[0].Rows[0]["islocdisplay"].ToString();
                        if (str == "1" || str=="True")
                        {
                            //正在显示，使之隐藏。
                            strset = "islocdisplay = 0";
                            bll.Updateadv(aid.ToString(), strset);
                        }
                        else
                        {
                            //正在隐藏，使之显示。
                            strset = "islocdisplay = 1";
                            bll.Updateadv(aid.ToString(), strset);
                        }
                        BindData();    
                        
                    }
                }
            }


        }
    }
}



